function httpRequest(options) {
	/*
	options: {
		method: String('GET'/'POST'...),
		dataType: String,
		url: String,
		data: Object,
		headers: Object,
		success: Function,
		error: Function
	}
	*/
    var xmlhttp = new XMLHttpRequest(),
		httpType = (options.method || 'GET').toUpperCase(),
		dataType = options.dataType || 'json',
		httpUrl = options.url || '',
		isAsync = options.async || true,
		sendData = options.data || {},
		success = options.success || function () {},
		error = options.error || function () {},
		httpHeaders = options.headers || {},
		requestData;
		
	switch(dataType){
		case 'json':
			requestData = JSON.stringify(sendData);
			break;
		case 'form-data':
			requestData = '';
			for(let k in sendData){
				if(sendData.hasOwnProperty(k)){
					requestData += `${k}=${sendData[k]}&`
				}
			}
			requestData
			break;
	}
	console.log(requestData);
		
	/*请求接收*/
	xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		  /*成功回调函数*/
		  success(xmlhttp.responseText);
		}else{
			/*失败回调函数*/
			error(xmlhttp.responseText);
		}
	}
	
	xmlhttp.open(httpType, httpUrl, isAsync);
	//发送合适的请求头信息
	httpHeaders['Content-Type'] = httpHeaders['Content-Type'] || 'application/x-www-form-urlencoded';
	for(let key in httpHeaders){
		if(httpHeaders.hasOwnProperty(key)){
			console.log(key, httpHeaders[key])
			xmlhttp.setRequestHeader(key, httpHeaders[key])
		}
	}
	xmlhttp.send(requestData);
}

// 使用
httpRequest({
	method: 'POST',
	url: 'https://pyramid-test.togocareer.com/asd',
	dataType: 'json',
	data: {
		name: 'hhhh',
		age: 21
	},
	headers: {
		// 'Content-Type': 'application/x-www-form-urlencoded'
		'Content-Type': 'application/json',
		'Authorization': 'asdasd'
	},
	success: function (res) {
		console.log(res);
	},
	error: function (err) {
		console.log(err);
	}
})